﻿
using System;
using System.Collections.Generic;
using System.Drawing.Text;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;

namespace WPF_Dialogs.Dialogs
{
	/// <summary>
	/// Interaction logic for FontDialog.xaml
	/// </summary>
	public partial class FontDialog : Window, IDialog
	{
		/// <summary>
        /// Gets or sets the dialog result value, which is the value that is returned from the <see cref="M:System.Windows.Window.ShowDialog"/> method.
        /// </summary>
        /// <value></value>
        /// <returns>A <see cref="T:System.Nullable`1"/> value of type <see cref="T:System.Boolean"/>. The default is false.</returns>
        /// <exception cref="T:System.InvalidOperationException">
        /// 	<see cref="P:System.Windows.Window.DialogResult"/> is set before a window is opened by calling <see cref="M:System.Windows.Window.ShowDialog"/>, or a window opened by calling <see cref="M:System.Windows.Window.Show"/>.</exception>
        public new EDialogResult DialogResult { set; get; }
        private System.Drawing.FontFamily[] fontFamilies;
        private string fontName;
        private int fontSize;
        private List<string> fontStyle;
        
        public FontDialog(string fontName = "", int fontSize = 10)
		{
			InitializeComponent();
			
			InstalledFontCollection installedFont = new InstalledFontCollection();
			fontFamilies = installedFont.Families;
			ListBoxItem item;
			
			for (int i = 0; i < fontFamilies.Length; i++)
			{
				item = new ListBoxItem();
				item.Content = fontFamilies[i].Name;
				this.listBoxFont.Items.Add(item);
			}
			
			FontName = fontName;
			FontSize = fontSize;
		}
		
        #region properties
        public string FontName
        {
        	get
        	{
        		return this.fontName;
        	}
        	set
        	{
        		this.fontName = value;
        		if (this.fontName != "")
        			this.listBoxFont.SelectedValue = this.fontName;
        	}
        }
        
        public int FontSize
        {
        	get
        	{
        		return this.fontSize;
        	}
        	set
        	{
        		this.fontSize = value;
        		this.listBoxSize.SelectedValue = this.fontSize.ToString();
        	}
        }
        #endregion
        
        #region public functions
		/// <summary>
        /// Shows the dialog.
        /// </summary>
        /// <returns>Result of the Dialog</returns>
        public EDialogResult showDialog()
        {
            this.ShowDialog();
            return this.DialogResult;
        }
        #endregion
        
		#region private functions
		private void listBoxFont_SelectionChanged(object sender, SelectionChangedEventArgs e)
		{
			
		}
		
		private void listBoxFontStyle_SelectionChanged(object sender, SelectionChangedEventArgs e)
		{
			
		}
		
		private void listBoxFontSize_SelectionChanged(object sender, SelectionChangedEventArgs e)
		{
			
		}
		
		private void initSize()
		{
			ListBoxItem l;
			for (int i = 2; i < 100; i++)
			{
				l = new ListBoxItem();
				l.Content = i.ToString();
				this.listBoxSize.Items.Add(l);
				if (i >= 20)
					i++;
				if (i >= 32)
					i = i + 2;
			}
		}
		#endregion
	}
}